package com.example.lenovo.demo1;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.btn_dialog1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showSimpleDialog();
            }
        });
    }
//第一种 简单的
    private void showSimpleDialog() {
        final String[] cities = {"北京","广州","深圳","上海"};
        final String[] xingbie = {"男","女","不知道"};
        final String[] aihao = {"跑步","唱歌","睡觉","打游戏","打代码"};
        final boolean isCheck[] = new boolean[5];

        //定义一个输入框
        final EditText editText1 = new EditText(MainActivity.this);
        final EditText editText2 = new EditText(MainActivity.this);

        View view = LayoutInflater.from(MainActivity.this)
                .inflate(R.layout.dialog_input,null,false);
        final EditText nameEdit = view.findViewById(R.id.edt_name);
        final EditText ageEdit = view.findViewById(R.id.edt_age);

        new AlertDialog.Builder(MainActivity.this)
                .setIcon(R.mipmap.ic_launcher)
                .setTitle("请选择您的姓名")
                .setView(view)

//                .setMultiChoiceItems(aihao, null, new DialogInterface.OnMultiChoiceClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialogInterface, int i, boolean b) {
//                        //保存每次点击后的值
//                        isCheck[i] =b;
//                        if(b){
//                            Toast.makeText(MainActivity.this,
//                                    "您添加了" +aihao[i],Toast.LENGTH_SHORT).show();
//                        }else{
//                            Toast.makeText(MainActivity.this,
//                                    "您取消了" +aihao[i],Toast.LENGTH_SHORT).show();
//                        }
//                    }
//                })
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int i) {
                        String name = nameEdit.getText().toString();
                        int age = Integer.parseInt(ageEdit.getText().toString());

                        Toast.makeText(MainActivity.this,
                                "您的姓名是" +name + "年龄是" + age,Toast.LENGTH_SHORT).show();
//                        StringBuffer buffer = new StringBuffer();
//                        for (int j=0;j<isCheck.length;j++){
//                            if(isCheck[j]){
//                                buffer.append(aihao[j]);
//                            }
//                        }
//                        Toast.makeText(MainActivity.this,
//                                "您的爱好有" +buffer,Toast.LENGTH_SHORT).show();
                    }
                })
//                .setSingleChoiceItems(xingbie, -1, new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int i) {
//                        Toast.makeText(MainActivity.this,
//                                "您的性别是" + xingbie[i] ,Toast.LENGTH_SHORT).show();
//                    }
//                })
               // .setMessage("今天是你的生日")
//                .setItems(cities, new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int i) {
//                        Toast.makeText(MainActivity.this,
//                                "您居住在"+ cities[i], Toast.LENGTH_SHORT).show();
//                    }
//                })

//                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int i) {
//                        Toast.makeText(MainActivity.this,
//                                "知道了",Toast.LENGTH_SHORT).show();
//                    }
//                })
//                .setNeutralButton("无所谓", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//                        Toast.makeText(MainActivity.this,
//                                "无所谓",Toast.LENGTH_SHORT).show();
//                    }
//                })
                .create()
                .show();
    }
}
